using UniversalAdmin.Application.Dtos;
using UniversalAdmin.Application.Dtos.Article;

namespace UniversalAdmin.Application.Services.Interfaces;

/// <summary>
/// 文章服务接口
/// </summary>
public interface IArticleService
{
    /// <summary>
    /// 根据ID获取文章
    /// </summary>
    /// <param name="id">文章ID</param>
    /// <returns>文章信息，不存在返回null</returns>
    Task<ArticleDto?> GetByIdAsync(Guid id);

    /// <summary>
    /// 分页获取文章列表
    /// </summary>
    /// <param name="request">分页请求参数</param>
    /// <returns>分页结果</returns>
    Task<PagedResult<ArticleDto>> GetPagedAsync(PageRequestDto request);

    /// <summary>
    /// 获取所有文章
    /// </summary>
    /// <returns>文章列表</returns>
    Task<List<ArticleDto>> GetAllAsync();

    /// <summary>
    /// 根据分类ID获取文章
    /// </summary>
    /// <param name="categoryId">分类ID</param>
    /// <returns>文章列表</returns>
    Task<List<ArticleDto>> GetByCategoryIdAsync(Guid categoryId);

    /// <summary>
    /// 根据状态获取文章
    /// </summary>
    /// <param name="status">文章状态</param>
    /// <returns>文章列表</returns>
    Task<List<ArticleDto>> GetByStatusAsync(string status);

    /// <summary>
    /// 创建文章
    /// </summary>
    /// <param name="createDto">创建文章DTO</param>
    /// <returns>创建后的文章信息</returns>
    Task<ArticleDto> CreateAsync(CreateArticleDto createDto);

    /// <summary>
    /// 更新文章
    /// </summary>
    /// <param name="updateDto">更新文章DTO</param>
    /// <returns>更新后的文章信息</returns>
    Task<ArticleDto> UpdateAsync(UpdateArticleDto updateDto);

    /// <summary>
    /// 删除文章 (软删除)
    /// </summary>
    /// <param name="id">文章ID</param>
    /// <returns></returns>
    Task DeleteAsync(Guid id);

    /// <summary>
    /// 搜索文章 (根据标题、内容、摘要搜索)
    /// </summary>
    /// <param name="keyword">搜索关键词</param>
    /// <returns>匹配的文章列表</returns>
    Task<List<ArticleDto>> SearchAsync(string keyword);

    /// <summary>
    /// 启用文章
    /// </summary>
    /// <param name="id">文章ID</param>
    /// <returns>操作结果</returns>
    Task<dynamic> EnableArticleAsync(Guid id);

    /// <summary>
    /// 禁用文章
    /// </summary>
    /// <param name="id">文章ID</param>
    /// <returns>操作结果</returns>
    Task<dynamic> DisableArticleAsync(Guid id);
}

/// <summary>
/// 分页结果类
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
public class PagedResult<T>
{
    /// <summary>
    /// 数据项列表
    /// </summary>
    public List<T> Items { get; set; } = new List<T>();

    /// <summary>
    /// 总记录数
    /// </summary>
    public long Total { get; set; }

    /// <summary>
    /// 当前页码
    /// </summary>
    public int PageIndex { get; set; }

    /// <summary>
    /// 每页大小
    /// </summary>
    public int PageSize { get; set; }

    /// <summary>
    /// 总页数
    /// </summary>
    public long TotalPages => (long)Math.Ceiling((double)Total / PageSize);
}
